package cn.edu.sgu.www.mhxysy.controller.equipment;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.entity.equipment.ForgeType;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.equipment.ForgeTypeService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "装备打造类型管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/forge_type", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ForgeTypeController {

    private final ForgeTypeService forgeTypeService;

    @Autowired
    public ForgeTypeController(ForgeTypeService forgeTypeService) {
        this.forgeTypeService = forgeTypeService;
    }

    @ApiOperation("查询全部装备打造类型")
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public JsonResult<List<ForgeType>> selectAll() {
        List<ForgeType> list = forgeTypeService.selectAll();

        return JsonResult.success(null, list);
    }

    @ApiOperation("通过ID查询装备打造类型")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public JsonResult<ForgeType> selectById(
            @ApiParam(name = "id", value = "装备打造类型ID", required = true)
            @NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
        ForgeType forgeType = forgeTypeService.selectById(id);

        return JsonResult.success(null, forgeType);
    }

    @ApiOperation("通过ID查询装备打造类型")
    @RequestMapping(value = "/selectByParentId", method = RequestMethod.GET)
    public JsonResult<ForgeType> selectByParentId(
            @ApiParam(name = "id", value = "装备打造类型ID", required = true)
            @NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
        ForgeType forgeType = forgeTypeService.selectByParentId(id);

        return JsonResult.success(null, forgeType);
    }

}